#include <iostream>
#include <set>

using namespace std;

struct X
{
    int x, y;
    X(int tx = 0, int ty = 0)
        :x(tx)
         ,y(ty)
    {}
    /**
     *bool operator< (const X &rhs)
     *{
     *    return this->y < rhs.y;
     *}
     */

    friend ostream& operator << (ostream& os, const X& x);
    friend bool operator < (const X &lhs, const X &rhs);
};

ostream& operator << (ostream& os, const X& x)
{
    os << x.x << " " << x.y << "   ";
    return os;
}
//不知道为什么非要用这种重载
bool operator < (const X &lhs, const X &rhs)
{
    //错误的比较函数，理解等价。
    if (lhs.x < rhs.x)
    {
        return true;
    }
    return lhs.y < rhs.y;
}

int main()
{
    set<X> sx;
    sx.insert(X(1, 2));
    sx.insert(X(2, 1));

    for (auto x : sx)
    {
        cout << x;
    }
    cout << endl;

    auto it = sx.find(X(1, 2));
    cout << *it;
    return 0;
}
